package com.mce.nebula.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * PHP配置服务
 * 对应Python的PhpConfigView功能
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PhpConfigService {
    
    /**
     * 获取PHP环境配置
     */
    public Map<String, Object> getPhpConfig() {
        Map<String, Object> config = new HashMap<>();
        
        // PHP版本列表
        List<String> versions = Arrays.asList(
            "5.6.11", "5.6.30", "5.6.35", 
            "7.0.16", "7.0.29", 
            "7.1.2", "7.1.16"
        );
        
        String defaultVersion = "5.6.11";
        
        // PHP扩展列表
        List<Map<String, Object>> extensions = Arrays.asList(
            createExtension("BCMath", "bcmath", "http://docs.php.net/bcmath", null),
            createExtension("Calendar", "calendar", "http://docs.php.net/calendar", null),
            createExtension("Exif", "exif", "http://docs.php.net/exif", "1.4"),
            createExtension("FTP", "ftp", "http://docs.php.net/ftp", null),
            createExtension("GD(支持PNG, JPEG 和 FreeType)", "gd", "http://docs.php.net/gd", "2.1.0"),
            createExtension("gettext", "gettext", "http://docs.php.net/gettext", null),
            createExtension("intl", "intl", "http://docs.php.net/intl", "1.1.0"),
            createExtension("mbstring", "mbstring", "http://docs.php.net/mbstring", "1.3.2"),
            createExtension("MySQL(PHP 5.5 版本已经停止支持，请使用 MySQLi 或 PDO)", "mysql", "http://docs.php.net/book.mysql", "mysqlnd 5.0.11-dev"),
            createExtension("PCNTL", "pcntl", "http://docs.php.net/pcntl", null),
            createExtension("Shmop", "shmop", "http://docs.php.net/shmop", null),
            createExtension("SOAP", "soap", "http://docs.php.net/soap", null),
            createExtension("SQLite3", "sqlite3", "http://docs.php.net/sqlite3", "0.7-dev"),
            createExtension("SQLite(PDO)", "pdo_sqlite", "http://docs.php.net/pdo_sqlite", "3.8.2"),
            createExtension("XMLRPC", "xmlrpc", "http://docs.php.net/xmlrpc", "0.51"),
            createExtension("XSL", "xsl", "http://docs.php.net/xsl", "1.1.28"),
            createExtension("APCu", "apcu", "http://pecl.php.net/package/apcu", "4.0.6"),
            createExtension("Blackfire", "blackfire", "http://blackfire.io/", "0.20.6"),
            createExtension("memcached", "memcached", "http://docs.php.net/memcached", "2.2.0"),
            createExtension("MongoDB", "mongodb", "http://docs.php.net/mongo", "1.6.6"),
            createExtension("NewRelic", "newrelic", "http://newrelic.com/php", "4.19.0.90"),
            createExtension("OAuth", "oauth", "http://docs.php.net/oauth", "1.2.3"),
            createExtension("PHPRedis", "redis", "http://pecl.php.net/package/redis", "2.2.7")
        );
        
        config.put("versions", versions);
        config.put("default_version", defaultVersion);
        config.put("extends", extensions);
        
        return config;
    }
    
    /**
     * 创建扩展信息
     */
    private Map<String, Object> createExtension(String name, String value, String url, String version) {
        Map<String, Object> extension = new HashMap<>();
        extension.put("name", name);
        extension.put("value", value);
        extension.put("url", url);
        extension.put("version", version);
        return extension;
    }
}
